<?php
namespace App\Query;

use App\Model\Product;

class ProductQuery extends \HyperfStore\Query
{
    // 构建模型
    protected static function build()
    {
        return Product::orderBy('id', 'desc');
    }
    
    // 渴望加载
    protected static function with()
    {
        return ['menu', 'daili'];
    }
    
    // 所属代理
    public static function daili($daili_id)
    {
        $model = self::model();
        
        if($daili_id)
        {
            $model->where('daili_id', $daili_id);
        }
        
        return $model;
    }
    
    // 有货状态
    public static function status($model = null)
    {
        return self::model($model)->where('count', '>', 0);
    }
}